from scapy.all import *
from arp_client import *

def sniffear(timeout=10):
	sniffed = sniff(timeout=timeout,filter="arp")

	#filtro solo los ARP
	return [packet for packet in sniffed if ARP in packet]
	
def sniff_print(sniffed):	
	for packet in sniffed:
		#Se que op==1 es who-has y op==2 es is-at
		if packet[ARP].op == 1:
			print packet[ARP].psrc + " asks who has " + packet[ARP].pdst
		elif packet[ARP].op == 2:
			print packet[ARP].psrc + " is at " + packet[ARP].hwsrc
	print "Total: " + str(len(sniffed))

if len(sys.argv) > 1:
	timeout = int(sys.argv[1])
else:
	timeout = 10

print "Sniffeando ARP por " + str(timeout) + " segundos"
sniff_print(sniffear(timeout))
